this.BX=this.BX||{};this.BX.Landing=this.BX.Landing||{};this.BX.Landing.UI=this.BX.Landing.UI||{};(function(e,t,n,a,i,r,l,s,o){"use strict";var c,d;var g=function(e){babelHelpers.inherits(a,e);babelHelpers.createClass(a,null,[{key:"getInstance",value:function e(){if(!a.instance){a.instance=new a("landing_create_page_panel",{title:i.Loc.getMessage("LANDING_CREATE_PAGE_PANEL_TITLE")})}return a.instance}}]);function a(e,n){var i;babelHelpers.classCallCheck(this,a);i=babelHelpers.possibleConstructorReturn(this,babelHelpers.getPrototypeOf(a).call(this,e,n));babelHelpers.defineProperty(babelHelpers.assertThisInitialized(i),"cache",new t.Cache.MemoryCache);babelHelpers.defineProperty(babelHelpers.assertThisInitialized(i),"range",null);t.Dom.addClass(i.layout,"landing-ui-panel-create-page");t.Dom.addClass(i.overlay,"landing-ui-panel-create-page");i.appendFooterButton(new BX.Landing.UI.Button.BaseButton("save_block_content",{text:BX.Landing.Loc.getMessage("BLOCK_SAVE"),onClick:i.onSave.bind(babelHelpers.assertThisInitialized(i)),className:"landing-ui-button-content-save"}));i.appendFooterButton(new BX.Landing.UI.Button.BaseButton("cancel_block_content",{text:BX.Landing.Loc.getMessage("BLOCK_CANCEL"),onClick:i.hide.bind(babelHelpers.assertThisInitialized(i)),className:"landing-ui-button-content-cancel"}));i.renderTo(window.parent.document.body);return i}babelHelpers.createClass(a,[{key:"getTitleField",value:function e(){return this.cache.remember("titleField",(function(){return new o.TextField({title:i.Loc.getMessage("LANDING_CREATE_PAGE_PANEL_FIELD_PAGE_TITLE"),textOnly:true})}))}},{key:"getCodeField",value:function e(){return this.cache.remember("codeField",(function(){return new o.TextField({title:i.Loc.getMessage("LANDING_CREATE_PAGE_PANEL_FIELD_PAGE_CODE"),textOnly:true})}))}},{key:"getForm",value:function e(){var t=this;return this.cache.remember("form",(function(){return new BX.Landing.UI.Form.BaseForm({fields:[t.getTitleField(),t.getCodeField()]})}))}},{key:"show",value:function e(){var n=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{},i=n.title,r=i===void 0?"":i;t.Dom.style(this.footer,"display",null);this.range=this.contextDocument.getSelection().getRangeAt(0);this.node=function(){if(BX.Landing.Block.Node.Text.currentNode&&BX.Landing.Block.Node.Text.currentNode.isEditable()){return BX.Landing.Block.Node.Text.currentNode}return o.TextField.currentField}();var l=r.replace(/^\w/,(function(e){return e.toUpperCase()}));this.getTitleField().setValue(l);var s=BX.translit(r,{change_case:"L",replace_space:"-",replace_other:""});this.getCodeField().setValue(s);this.clear();this.appendForm(this.getForm());return babelHelpers.get(babelHelpers.getPrototypeOf(a.prototype),"show",this).call(this)}},{key:"getSuccessMessage",value:function e(n){var a=l.Env.getInstance().getOptions();var r=a.params.sef_url.landing_view;var s=a.site_id;var o=r.replace("#site_show#",s).replace("#landing_edit#",n);return t.Tag.render(c||(c=babelHelpers.taggedTemplateLiteral(['\n\t\t\t<div class="landing-ui-panel-create-page-success">\n\t\t\t\t<div class="landing-ui-panel-create-page-success-header">\n\t\t\t\t\t','\n\t\t\t\t</div>\n\t\t\t\t<div class="landing-ui-panel-create-page-actions">\n\t\t\t\t\t<a href="','" target="_blank">',"</a> &nbsp;\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t"])),i.Loc.getMessage("LANDING_CREATE_PAGE_PANEL_SUCCESS_MESSAGE_TITLE"),o,i.Loc.getMessage("LANDING_CONTENT_PANEL_TITLE"))}},{key:"getFailMessage",value:function e(){return this.cache.remember("failMessage",(function(){return t.Tag.render(d||(d=babelHelpers.taggedTemplateLiteral(['\n\t\t\t\t<div class="landing-ui-panel-create-page-fail">\n\t\t\t\t\t<div class="landing-ui-panel-create-page-fail-header">\n\t\t\t\t\t\t',"\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t"])),i.Loc.getMessage("LANDING_CREATE_PAGE_PANEL_FAIL_MESSAGE_TITLE"))}))}},{key:"onSave",value:function e(){var a=this;var i=r.Backend.getInstance();var o=this.getTitleField().getValue();var c=BX.translit(this.getCodeField().getValue(),{change_case:"L",replace_space:"-",replace_other:""});var d=l.Env.getInstance().getOptions(),g=d.folder_id;var u=new n.Loader;this.clear();u.show(this.body);void i.createPage({title:o,code:c,folderId:g}).then((function(e){return new Promise((function(t){setTimeout((function(){return t(e)}),500)}))})).then((function(e){u.hide();if(t.Type.isNumber(e)){var n=a.getSuccessMessage(e);if(l.Env.getInstance().getType()==="KNOWLEDGE"||l.Env.getInstance().getType()==="GROUP"){var i=n.querySelector("a");if(i){t.Event.bind(i,"click",(function(e){e.preventDefault();void s.SliderHacks.reloadSlider(i.href,window.parent)}))}}t.Dom.append(n,a.content);var r={href:"#landing".concat(e)};a.contextDocument.getSelection().removeAllRanges();a.contextDocument.getSelection().addRange(a.range);a.node.enableEdit();var o=t.Text.encode("".concat(r.href).concat(t.Text.getRandom()));var c=a.contextDocument.getSelection();a.contextDocument.execCommand("createLink",false,o);var d=c.anchorNode.parentElement.parentElement.parentElement.querySelector('[href="'.concat(o,'"]'));if(d){t.Dom.attr(d,"href",r.href);t.Dom.attr(d,"target",r.target);if(t.Type.isString(r.text)){d.innerText=r.text}if(t.Type.isPlainObject(r.attrs)){t.Dom.attr(d,r.attrs)}}t.Dom.style(a.footer,"display","none")}else{t.Dom.append(a.getFailMessage(),a.content)}}))}}]);return a}(a.Content);e.CreatePage=g})(this.BX.Landing.UI.Panel=this.BX.Landing.UI.Panel||{},BX,BX,BX.Landing.UI.Panel,BX.Landing,BX.Landing,BX.Landing,BX.Landing,BX.Landing.UI.Field);
//# sourceMappingURL=createpage.bundle.map.js